<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Supplier_m extends CI_Model {
        
        function get_all_supplier() {
            $q = $this->db->where('s_status', 'active')->get('supplier');
            if($q->num_rows() > 0) {
                return $q->result_array();
            }else{
                return FALSE;
            }
        }
        
        function get_supplier($id) {
            $q = $this->db->where('supplier_id', $id)->get('supplier');
            if($q->num_rows() > 0) {
                return $q->row();
            }else{
                return FALSE;
            }
        }
        
        function get_services($id) {
            $q = $this->db->where('supplier_id', $id)->get('supplier');
            if($q->num_rows() > 0) {
                return $q->row();
            }else{
                return FALSE;
            }
        }
        
        function insert_supplier($data) {
            $this->db->insert('supplier', $data);
            return $this->db->insert_id();
        }
        
        function update_supplier($id, $data) {
            $supplier_info = array(
                'company' => $data['company'],
                'contact_person' => $data['contact_person'],
                's_num' => $data['s_num'],
                's_email' => $data['s_email'],
                'services' => $data['services'],
                's_address' => $data['s_address'],
            );
            $this->db->where('supplier_id', $id)->update('supplier', $supplier_info);
            return $this->db->affected_rows();
        }
        
        function delete_supplier($supplier_id) {
            for($i=0;$i<sizeof($supplier_id);$i++){
                $this->db->where('supplier_id', $supplier_id[$i])->delete('supplier'); 
            }
        }
    }
